package com.zyf.chapter02.behavior.memento.v1;

import java.util.Scanner;

/**
 * 应用类
 * @author yifeng
 */
public class ApplicationMain {
    public static void main(String[] args) {
        InputText inputText = new InputText();
        SnapshotHolder snapshotHolder = new SnapshotHolder();
        Scanner scanner = new Scanner(System.in);
        /**
         * 输入 hello ，stack 压入 hello
         * 输入 world，stack 压入 helloworld
         * 输入 :undo stack 弹出，helloworld，剩下 hello
         */
        while (scanner.hasNext()) {
            String input = scanner.next();
            if (input.equals(":list")) {
                System.out.println(inputText.getText());
            } else if (input.equals(":undo")) {
                InputText snapshot = snapshotHolder.popSnapshot();
                inputText.setText(snapshot.getText());
            } else {
                snapshotHolder.pushSnapshot(inputText);
                inputText.append(input);
            }
        }
    }
}
